<?php

class TransactionController extends Zend_Controller_Action
{
    protected $db;
    
    public function init()
    {
        /* Initialize action controller here */
        /*if (!Zend_Auth::getInstance()->hasIdentity()) {
            $param = array(
            'action' => 'index',
            'controller' => 'index',
            'msg' => 'Session Timeout silahkan login kembali !'
            );
            $this->_redirect($this->view->url($param, 'default', true));
        }
         * 
         */
        
        $session = new Zend_Session_Namespace('Zend_Auth');
        $this->sess = $session->data;

        if(!isset($this->sess)){
            $param = array(
            'action' => 'index',
            'controller' => 'index',
            'msg' => 'Session Timeout silahkan login kembali !'
            );
            $this->_redirect($this->view->url($param, 'default', true));
        }

        
        $this->transType = new Application_Model_TransType();

        $this->request = $this->getRequest();
        $this->param = $this->request->getParams();
    }

    public function indexAction()
    {
        $sBy = $this->param['sBy'];
        $key = $this->param['key'];
        $start = $this->param['start'];
        $limit = $this->param['limit'];
        
        $data = $this->transType->getTransType($sBy, $key, $start, $limit);
        $temp = array();

        for($k = 0;$k<count($data);$k++) {
          $temp[$k]['trans_type_id']   = $data[$k]['trans_type_id'];
          $temp[$k]['trans_type_code'] = $data[$k]['trans_type_code'];
          $temp[$k]['trans_type_desc'] = $data[$k]['trans_type_desc'];
        }

        $this->view->id = json_encode($temp);
    }

    
    public function addAction()
    {
        $transTypeCode  = $this->param['transTypeCode'];
        $transTypeDesc  = $this->param['transTypeDesc'];

        $data = $this->transType->addTransType($transTypeCode, $transTypeDesc);
        
        $temp = array();
        
        for($k = 0;$k<count($data);$k++) {
          $temp[$k]['trans_type_id']    = $data[$k]['trans_type_id'];
        }

        $this->view->id = json_encode($temp);
    }


    public function editAction()
    {
        $transTypeId    = $this->param['transTypeId'];
        $transTypeCode  = $this->param['transTypeCode'];
        $transTypeDesc  = $this->param['transTypeDesc'];

        $data = $this->transType->editTransType($transTypeId, $transTypeCode,
                    $transTypeDesc);

        $temp = array();

        for($k = 0;$k<count($data);$k++) {
          $temp[$k]['trans_type_id']    = $data[$k]['trans_type_id'];
        }

        $this->view->id = json_encode($temp);
    }


    public function delAction()
    {
        $transTypeId   = $this->param['transTypeId'];

        $data = $this->transType->delTransType($transTypeId);

        $temp = array();
        
        for($k = 0;$k<count($data);$k++) {
          $temp[$k]['trans_type_id']    = $data[$k]['trans_type_id'];
        }

        $this->view->id = json_encode($temp);
    }
   
}

